from django.db import models
from string import capwords
import time

class Member(models.Model):
	first_name=models.CharField(
		max_length=200, 
		verbose_name="First Name",
		help_text="First name of the individual.",
	)
	last_name=models.CharField(
		max_length=200,
		verbose_name="Last Name",
		help_text="Last name of the individual.",
	)
	email=models.CharField(
		max_length=200,
		verbose_name="Email Address",
		help_text="Email of the individual (e.g. jsmith@example.com)",
	)
	phone=models.CharField(
		max_length=200,
		verbose_name="Phone Number",
		help_text="Phone number (e.g. 1234567890)",
	)

	class Meta:
		verbose_name="Member"
		verbose_name_plural="Members"

	def __unicode__(self):
		return u"%s %s" % (capwords(self.first_name), capwords(self.last_name))

	def last_name_first(self):
		return u"%s, %s" % (capwords(self.last_name), capwords(self.first_name))

	def first_name_first	(self):
		return u"%s %s" % (capwords(self.first_name), capwords(self.last_name))

class State(models.Model):
	short_name=models.CharField(
		max_length=10,
		verbose_name="Short State Name",
		help_text="Short state name (e.g. CA, HI, AK, etc.)",
	)
	long_name=models.CharField(
		max_length=10,
		verbose_name="Long State Name",
		help_text="Long state name(e.g. California, Hawaii, Alaska, etc.)",
	)

	def __unicode__(self):
		return u"%s - %s" % (self.short_name,self.long_name)

	def sname(self):
		return u"%s" % (self.short_name)

	def lname(self):
		return u"%s" % (self.long_name)

	def full_name(self):
		return u"%s - %s" % (self.short_name,self.long_name)

class Address(models.Model):
	name=models.CharField(
		max_length=200,
		verbose_name="Descriptive Name",
		help_text="Descriptive name for this address.",
	)
	street_address=models.CharField(
		max_length=200,
		verbose_name="Street Address",
		help_text="Street address (e.g. 1234 Koala Street)",
	)
	city=models.CharField(
		max_length=200,
		verbose_name="City",
		help_text="City (e.g. San Francisco)",
	)
	state=models.ForeignKey(
		State,
		verbose_name="State",
		help_text="Select the address state/province.",
	)
	postalcode=models.IntegerField(
		verbose_name="Postal Code",
		help_text="Postal (ZIP) code of address.",
	)

	class Meta:
		verbose_name="Address"
		verbose_name_plural="Addresses"

	def __unicode__(self):
		return u"%s" % (self.name)

	def full_address(self):
		return u"%s, %s, %s %s" % (self.street_address, self.city, self.state.short_name, self.postalcode)

class Meeting(models.Model):
	address=models.ForeignKey(
		Address,
		verbose_name="Meeting Address",
		help_text="Where will the meeting be held?",
	)
	name=models.CharField(
		max_length=200,
		verbose_name="Meeting Name",
		help_text="Give a short descriptive name for the meeting (e.g. General Meeting).",
	)
	start_datetime=models.DateTimeField(
		"Date/Time meeting starts",
		help_text="Date: YYYY-MM-DD Time: hh:mm:ss",
	)
	end_datetime=models.DateTimeField(
		"Date/Time meeting ends",
		help_text="Date: YYYY-MM-DD Time: hh:mm:ss",
	)

	class Meta:
		verbose_name="Meeting"
		verbose_name_plural="Meetings"

	def __unicode__(self):
		return u"%s: %s" % (self.name, self.start_datetime)

	def duration(self):
		return (self.end_datetime - self.start_datetime)

class Role(models.Model):
	name=models.CharField(
		max_length=200,
		verbose_name="Role",
		help_text="Meeting member defined role.",
	)

	class Meta:
		verbose_name="Role"
		verbose_name_plural="Roles"

	def __unicode__(self):
		return u"%s" % (capwords(self.name))

class Attendance(models.Model):
	role=models.ForeignKey(
		Role,
		verbose_name="Role",
	)
	member=models.ForeignKey(
		Member,
		verbose_name="Member",
	)
	meeting=models.ForeignKey(
		Meeting,
		verbose_name="Meeting",
	)

	class Meta:
		verbose_name="Attendance"
		verbose_name_plural="Attendance"

	def __unicode__(self):
		return u"%s %s (%s)" % (self.meeting.address, self.member.first_name,self.role.name)

class Sound(models.Model):
	name=models.CharField(
		max_length=200,
		verbose_name="Interjection words",
		help_text="Define an interjection word to track.",
	)

	class Meta:
		verbose_name="Sound"
		verbose_name_plural="Sounds"

	def __unicode__(self):
		return u"%s" % (self.name)

class ParticipationType(models.Model):
	name=models.CharField(
		max_length=200,
		verbose_name="Participation Type",
		help_text="Define the type of member participation (e.g. assigned speech, table topic, etc.)",
	)
	description=models.TextField(
		verbose_name="Participation Type Description",
		help_text="Description of the defined participation type.",
	)

	class Meta:
		verbose_name="Participation Type"
		verbose_name_plural="Participation Types"

	def __unicode__(self):
		return u"%s" % (self.name)

class Participation(models.Model):
	name=models.CharField(
		max_length=200,
		verbose_name="Name",
		help_text="Descriptive name of this instance of participation.",
		)
	attendance=models.ForeignKey(
		Attendance,
		verbose_name="Attendance",
	)
	participation_type=models.ForeignKey(
		ParticipationType,
		verbose_name="Participation Type",
	)

	class Meta:
		verbose_name="Participation"
		verbose_name_plural="Participations"

	def __unicode__(self):
		return u"%s %s" % (self.participation_type.name, self.attendance.member.first_name)

class Comment(models.Model):
	observer=models.ForeignKey(
		Member,
		verbose_name="Observer",
		help_text="Member giving the comment.",
	)
	participant=models.ForeignKey(
		Participation,
		verbose_name="Participation",
		help_text="Participation instance applicable to the comment.",
	)
	body=models.TextField(
		verbose_name="Comment Body",
		help_text="Comments from other members.",
	)

	class Meta:
		verbose_name="Comment"
		verbose_name_plural="Comments"

	def __unicode__(self):
		return u"%s" % (self.body)

class TrackSound(models.Model):
	sound=models.ForeignKey(
		Sound,
		verbose_name="Sound",
		help_text="Sound to track.",
	)
	participant=models.ForeignKey(
		Participation,
		verbose_name="Participation",
		help_text="Participation instance applicable to the sound count.",
	)
	count=models.IntegerField(
		verbose_name="Sound Count",
		help_text="Sound counter",
	)

	class Meta:
		verbose_name="Track Sound"
		verbose_name_plural="Track Sounds"

	def __unicode__(self):
		return u"%s: %d" % (self.sound.name, self.count)




